package com.bilibili.java.books.util;

import java.util.List;

/**
 * 页的工具类：主要实现翻页功能
 * @author Administrator
 *
 */
public class Footet<T> {
	
	
	private int pagination;//页码
	
	private int record=4;//每次取值的纪录数
	private List<T> list;//当前取出的纪录显示集合对象
	private int totalRecord;//总纪录条数
	
	public Footet(int pagination) {
		super();
		this.pagination = pagination;
	}
	
	
	@Override
	public String toString() {
		return "Footet [pagination=" + pagination + ", record=" + record + ", list=" + list + ", totalRecord="
				+ totalRecord + "]";
	}


	public int getPagination() {
		return pagination;
	}
	public void setPagination(int pagination) {
		//当传入的页码大于总页码时
		if(pagination>getPageCount()) {
			//就给传入的页码赋予总页码的值(也就是最后一页的值)
			pagination=getPageCount();
		}
		//当传入的页码小于1就默认为第一页
		if(pagination<1) {
			pagination=1;
		}
		
		this.pagination = pagination;
	}
	public int getRecord() {
		return record;
	}
	public void setRecord(int record) {
		this.record = record;
	}
	public List<T> getList() {
		return list;
	}
	public void setList(List<T> list) {
		this.list = list;
	}
	public int getTotalRecord() {
		return totalRecord;
	}
	public void setTotalRecord(int totalRecord) {
		this.totalRecord = totalRecord;
	}
	
	/**
	 * 获得总页码的方法
	 * @return
	 */
	public  int getPageCount() {
		int pageCount=totalRecord/record;
		
		if(totalRecord%record!=0) {
			pageCount++;
		}
		return pageCount;
		
	}
	
	
}
